home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
msqc25t1
/
spawn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-31
|
2KB
|
57 lines
/* spawn.c: Passes modified environment to chile process */
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <dos.h>
#include <errno.h>
#include <graph.h>
void main()
{
char newvar[] = "XYZ=7890", /* New environment srting */
*envp [5], /* pointers to env strings */
childpath[] = "CHILD.EXE", /* path to child */
*args[] = {"CHILD.EXE", /* command line arguments */
"A1", "A2", NULL},
comspec [64], path [64], prompt [64];
int status;
/* Show current environment */
_clearscreen (_GCLEARSCREEN);
puts ("In parent, orginal environment is:\n");
system ("SET");
/* Get current environment strings for child */
sprintf (comspec, "COMSPEC= %s", getenv ("COMSPEC"));
sprintf (path, "PATH=%s", getenv ("PATH"));
sprintf (prompt, "PROMPT=%s", getenv ("PROMPT"));
/* Load pointer array for environment srtings */
envp [0] = comspec;
envp [1] = path;
envp [2] = prompt;
envp [3] = newvar;
envp [4] = NULL;
/* Spawn the child */
status = spawnvpe (P_WAIT, childpath, args, envp);
printf ("\n\nIn parent, spawn status = %d", status);
/* Check for, report error */
if (status != EXIT_SUCCESS) { /* child exit status */
puts ("\nError occurred:\n");
switch (errno) {
case E2BIG: puts ("Argument list to long"); break;
case EINVAL: puts ("Invalid argument"); break;
case ENOENT: puts ("Bad path or filename"); break;
case ENOEXEC: puts ("Exec format error"); break;
case ENOMEM: puts ("Not enough memory"); break;
}
} else
puts (" (Successful)");
}